package com.xyy.yueshijia.topic;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.xyy.yueshijia.R;

import java.util.ArrayList;

/**
 * Created by Asus on 2017/2/7.
 */

public class TopicFragment extends Fragment {



    private String[] titles = {"视频", "榜单", "地图", "知识", "人文", "活动"};
    private TabLayout tablayout;
    private ViewPager viewpager;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.topicfragment, container, false);
        tablayout = (TabLayout) view.findViewById(R.id.class_tablayout);
        viewpager = (ViewPager) view.findViewById(R.id.class_viewpager);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        ArrayList<Fragment> fragments=new ArrayList<>();
        /*for (int i = 0, len=titles.length; i < len; i++) {
            fragments.add(new HoudongFragment());
        }*/
        fragments.add(new ShipinFragment());
        fragments.add(new BangdanFragment());
        fragments.add(new MapFragment());
        fragments.add(new ZhishiFragment());
        fragments.add(new RenwenFragment());
        fragments.add(new HoudongFragment());


        tablayout.setTabMode(TabLayout.MODE_SCROLLABLE);

        TopicFragmentAdapter adapter=new TopicFragmentAdapter(getChildFragmentManager(),fragments,titles);

        viewpager.setOffscreenPageLimit(fragments.size());
        viewpager.setAdapter(adapter);
        tablayout.setupWithViewPager(viewpager);

    }



}
